package com.demo.my.Controller;

import com.demo.my.Entity.Department;
import com.demo.my.Entity.Employee;
import com.demo.my.Entity.Position;
import com.demo.my.Service.DepartmentService;
import com.demo.my.Service.EmployeeService;
import com.demo.my.Service.PositionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/PUPEmployee")
public class PreUpdateEmployeeServlet extends HttpServlet {
    private DepartmentService departmentService=new DepartmentService();
    private EmployeeService employeeService=new EmployeeService();
    private PositionService positionService=new PositionService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String id = req.getParameter("id");
        try {
            Employee employee=employeeService.getEmployeeById(id);
            List<Department> depList = departmentService.getDepList();
            List<Position> positionList = positionService.getPositionList();
            req.setAttribute("employee",employee);
            req.setAttribute("departments",depList);
            req.setAttribute("positions",positionList);
            req.getRequestDispatcher("/jsp/admin/employee_update.jsp").forward(req,resp);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    }
}
